package com.rest.demo.functional.api;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Administrator
 * @decription
 * @Date 2018-01-31 11:24
 */
public class FileApi {

    public static void main(String[] args) throws IOException {
        try(Stream<Path> stream = Files.list(Paths.get("F:\\guns-framework\\childstory"))) {
            String join = stream.map(String::valueOf)
//                    .filter(str -> str.contains("."))
                    .sorted()
                    .collect(Collectors.joining(";\n"));
            System.out.println(join);
        } catch (IOException e) {
            e.printStackTrace();
        }

        Path start = Paths.get("F:\\guns-framework\\childstory");
        List<String> javaPathList = new ArrayList<String>();
        try(Stream<Path> stream = Files.find(start,10,(path,attr) ->
            String.valueOf(path).endsWith(".java")
        )) {
            javaPathList = stream.map(String::valueOf)
                    .sorted()
                    .collect(Collectors.toList());
        }catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(javaPathList.size());

        String str = Files.readAllLines(Paths.get(javaPathList.get(0)))
                .stream()
                .collect(Collectors.joining("\n"));
        System.out.println(str);
    }
}
